﻿Imports System.Web.UI

Namespace DotNetNuke.Modules.ActiveForums

    Partial Public Class admin_upgrade
        Inherits ActiveAdminBase

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Server.ScriptTimeout = Integer.MaxValue
        End Sub

        Private Sub cbUpgrade_Callback(ByVal sender As Object, ByVal e As Controls.CallBackEventArgs) Handles cbUpgrade.Callback
            Dim upFilePath As String = Server.MapPath("~/desktopmodules/activeforums/upgrade4x.txt")
            Dim err As String = "Success"
            Try
                If IO.File.Exists(upFilePath) Then
                    Dim s As String = Utilities.GetFileContent(upFilePath)
                    err = DotNetNuke.Entities.Portals.PortalSettings.ExecuteScript(s)
                    IO.File.Delete(upFilePath)
                End If
            Catch ex As Exception
                If TypeOf ex Is UnauthorizedAccessException And String.IsNullOrEmpty(err) Then
                    err = "<span style=""font-size:14px;font-weight:bold;"">The forum data was upgraded successfully, but you must manually delete the following file:<br /><br />" & upFilePath & "<br /><br />The upgrade is not complete until you delete the file indicated above.</span>"
                Else
                    err = "<span style=""font-size:14px;font-weight:bold;"">Upgrade Failed - Please go to the <a href=""http://www.activemodules.com/community/helpdesk.aspx"">Active Modules Help Desk</a> to report the error indicated below:<br /><br />" & ex.Message & "</span>"
                End If

            End Try
            Dim lit As New LiteralControl
            If String.IsNullOrEmpty(err) Then
                err = "<script type=""text/javascript"">LoadView('home');</script>"
            End If
            lit.Text = err
            lit.RenderControl(e.Output)
        End Sub
    End Class
End Namespace